package com.videoplayer;

import java.util.ArrayList;
import java.util.List;

import com.util.CirclePageIndicator;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class WelcomeActivity extends Activity {
	private ViewPager mPager;
	private List<View> mListViews;
//	protected static final int[] CONTENT = new int[] {
//			R.drawable.welcome1, R.drawable.welcome2,
//			R.drawable.welcome3, R.drawable.welcome4, };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setFormat(PixelFormat.RGBA_8888);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.welcome_activity);
		mListViews = new ArrayList<View>();
		Resources r = getResources();
		Bitmap[] resource = new Bitmap[4];
	      resource[0] = BitmapFactory.decodeResource(r, R.raw.welcome1);
	      resource[1]= BitmapFactory.decodeResource(r, R.raw.welcome2);
	      resource[2]= BitmapFactory.decodeResource(r, R.raw.welcome3);
	      resource[3]= BitmapFactory.decodeResource(r, R.raw.welcome4);
		for (int i = 0; i < 4; i++) {
			if (i != 3) {
				ImageView iv = new ImageView(WelcomeActivity.this);
				iv.setBackgroundDrawable(new BitmapDrawable(resource[i]));
//				Drawable drawable32 = iv.getDrawable();
//				drawable32.setDither(true);
				mListViews.add(iv);
			}else{
				LinearLayout ly = new LinearLayout(WelcomeActivity.this);
//				ly.setImageBitmap(resource[i]);
				ly.setBackgroundDrawable(new BitmapDrawable(resource[i]));
				ly.setGravity(Gravity.CENTER_HORIZONTAL);
				ly.setPadding(0, 80, 0, 0);
				Button btnStrat = new Button(WelcomeActivity.this);
				btnStrat.setText("那我们就开始吧");
				btnStrat.setBackgroundResource(R.drawable.btn_normal);
				btnStrat.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						WelcomeActivity.this.finish();
					}
				});
				ly.addView(btnStrat);
				mListViews.add(ly);
			}
		}
		AwesomePagerAdapter adapter = new AwesomePagerAdapter();

		mPager = (ViewPager) findViewById(R.id.pager);
		mPager.setAdapter(adapter);

		CirclePageIndicator indicator = (CirclePageIndicator) findViewById(R.id.indicator);
		indicator.setViewPager(mPager);
	}

	private class AwesomePagerAdapter extends PagerAdapter {

		@Override
		public int getCount() {
			return mListViews.size();
		}

		@Override
		public Object instantiateItem(View collection, int position) {

			((ViewPager) collection).addView(mListViews.get(position), 0);

			return mListViews.get(position);
		}

		@Override
		public void destroyItem(View collection, int position, Object view) {
			((ViewPager) collection).removeView(mListViews.get(position));
		}

		@Override
		public boolean isViewFromObject(View view, Object object) {
			return view == (object);
		}

		@Override
		public void finishUpdate(View arg0) {
		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {
		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
		}

	}
}